package aspects;

import java.util.ArrayList;

public abstract aspect SubjectObserver {
	
// Coupe et advice
	abstract pointcut stateChanges(Subject s); 
	after(Subject s) : stateChanges(s) {
		for (Observer obs : s.getObservers()) {
			obs.update();
		}
	}
	
// Subject	
	private ArrayList<Observer> Subject.observers=new ArrayList<Observer>();
	public void Subject.addObserver(Observer obs) {
		getObservers().add(obs);
		obs.setSubject(this);
	}
	public void Subject.removeObserver(Observer obs) {
		getObservers().remove(obs);
		obs.setSubject(null);
	}
	public ArrayList<Observer> Subject.getObservers() {
		return observers;
	}

//Observer
	private Subject Observer.subject;
	public void Observer.setSubject(Subject s) {
		subject=s;
	}
	public Subject Observer.getSubject() {
		return subject;
	}
	
	
}
